package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.CrmSignDB;

import java.util.List;

/**
 * Created by mlli on 2017/8/23.
 */

public class TripSignAdapter extends RecyclerView.Adapter {

    private Context context;
    private List<CrmSignDB> list;

    public TripSignAdapter(Context context, List<CrmSignDB> list) {
        this.context = context;
        this.list = list;
    }

    public void setList(List<CrmSignDB> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_crm_sign, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        MyHolder myHolder = (MyHolder) holder;
        CrmSignDB signDB = list.get(position);
        myHolder.location.setText(signDB.getLocation());
        myHolder.time.setText(signDB.getTime());
        myHolder.v2.setVisibility(View.VISIBLE);
        if (position==list.size()-1)myHolder.v2.setVisibility(View.GONE);

    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
        TextView time;
        TextView location;
        View v2;

        public MyHolder(View itemView) {
            super(itemView);
            time = (TextView) itemView.findViewById(R.id.time);
            location = (TextView) itemView.findViewById(R.id.location);
            v2 = itemView.findViewById(R.id.v2);
        }
    }
}
